package org.wyy.vm.service.impl;

import java.util.List;

import org.wyy.vm.dao.IVideoDao;
import org.wyy.vm.dao.impl.VideoDaoImpl;
import org.wyy.vm.entity.Video;
import org.wyy.vm.service.IVideoService;

public class VideoServiceImpl implements IVideoService {
	
	private static IVideoDao videoDao = new VideoDaoImpl();

	@Override
	public List<Video> getAllVideos() {
		return videoDao.searchByName(null);
	}

	@Override
	public List<Video> searchByName(String name) {
		return videoDao.searchByName(name);
	}

	@Override
	public Video getById(long id) {
		return videoDao.getById(id);
	}

	@Override
	public void addVideo(Video video) {
		videoDao.add(video);		
	}

	@Override
	public void deleteVideo(long id) {
		videoDao.delete(id);
	}

	@Override
	public void updateVideo(Video video) {
		videoDao.update(video);
	}

	@Override
	public Object[] getJTableColumnNames() {
		Object[] columnNames = { "编号", "名称", "演员", "简介" };
		return columnNames;
	}

	@Override
	public Object[][] getJTableData() {
		
		List<Video> videoList =  getAllVideos();
		
//		if(videoList.size() == 0) {
//			return null;
//		}
		
		Object[][] data = new Object[videoList.size()][] ;
		
		for(int i = 0 ; i < videoList.size() ; ++i) {
			data[i] = new Object[4];
			data[i][0] = videoList.get(i).getId();
			data[i][1] = videoList.get(i).getName();
			data[i][2] = videoList.get(i).getActors();
			data[i][3] = videoList.get(i).getContent();
		}
		
		return data;
	}

}
